package com.sylli.oeuf.server.game.logic;

import java.util.Collection;

import com.sylli.oeuf.server.game.logic.BattleActor.Type;
import com.sylli.oeuf.server.game.logic.action.ActionAddBuff;
import com.sylli.oeuf.server.game.logic.action.ActionAddDebuff;
import com.sylli.oeuf.server.game.logic.action.CombatLog;
import com.sylli.oeuf.server.game.logic.action.ConsumeMana;
import com.sylli.oeuf.server.game.logic.action.Damage;
import com.sylli.oeuf.server.game.logic.action.Healing;
import com.sylli.oeuf.server.game.logic.action.StatusModifier;
import com.sylli.oeuf.server.game.logic.invocation.InvocationEvent;
import com.sylli.oeuf.server.game.logic.invocation.InvocationParameter;
import com.sylli.oeuf.server.object.transferable.PostBattleResponseTO;

public class ActionProductProcessor {

	public static void process(Collection<ActionProduct> aps, InvocationParameter param, 
			PostBattleResponseTO response) {
		for (ActionProduct ap : aps) {
			if (ap instanceof Damage) {
				Damage dmg = (Damage) ap;
				ap.source.dispatchEvent(InvocationEvent.STD_IE_ON_DEAL_DAMAGE, dmg);
				ap.target.API__modifyHp(-1 * dmg.getValue());
			} else if (ap instanceof Healing) {
				Healing h = (Healing) ap;
				ap.source.dispatchEvent(InvocationEvent.STD_IE_ON_CAST_HEAL, h);
				ap.target.dispatchEvent(InvocationEvent.STD_IE_ON_RECIEVE_HEAL, h);
				ap.target.API__modifyHp(h.getValue());
			} else if (ap instanceof ActionAddDebuff) {
				ActionAddDebuff adb = (ActionAddDebuff) ap;
				ap.target.API__addDeBuff(adb.getDebufftoadd(), param);
			} else if (ap instanceof ActionAddBuff) {
				ActionAddBuff ab = (ActionAddBuff) ap;
				ap.target.API__addBuff(ab.getBufftoadd(), param);
			} else if (ap instanceof StatusModifier) {
				StatusModifier sm = (StatusModifier) ap;
				sm.target.API__modifyStat(sm.getModValue());
			} else if (ap instanceof ConsumeMana) {
				ConsumeMana cm = (ConsumeMana) ap;
				cm.source.dispatchEvent(InvocationEvent.STD_IE_ON_USE_MANA, cm);
				cm.source.API__modifyMp(-1 * cm.getValue());
			} else if (ap instanceof CombatLog) {
				CombatLog str = (CombatLog) ap;
				if (ap.source.getType().equals(Type.Player)) {
					response.addPlayerEventMessage(str.get() + "[" + ap.target.getCurrHealth() + "]");
				} else {
					response.addMonsterEventMessage(str.get()+ "[" + ap.target.getCurrHealth() + "]");
				}
			} else {
				
			}
		}
	}
	
}
